package Test02;

import java.util.ArrayList;
import java.util.List;

class BankCard {


    private String cardNumber;
    private String cardHolderName;
    private double balance;
    private List<Transaction> transactions;

    public BankCard(String cardNumber, String cardHolderName) {
        this.cardNumber = cardNumber;
        this.cardHolderName = cardHolderName;
        this.balance = 0.0;
        this.transactions = new ArrayList<>();
    }

    public void setTransactions(Transaction transaction) {
        this.transactions.add(transaction);
        if (transaction.getType().equals("收入")) {
            balance += transaction.getAmount();
        } else if (transaction.getType().equals("支出")) {
            balance -= transaction.getAmount();
        } else {
            System.out.println("交易出错，交易类型仅支持收入与支出！");
        }

    }

//Getter Setter and toString methods...


    @Override
    public String toString() {
        return "Test02.BankCard{" +
                "cardNumber='" + cardNumber + '\'' +
                ", cardHolderName='" + cardHolderName + '\'' +
                ", balance=" + balance +
                ", transactions=" + transactions +
                '}';
    }

    public String getCardNumber() {
        return cardNumber;
    }

    public void setCardNumber(String cardNumber) {
        this.cardNumber = cardNumber;
    }

    public String getCardHolderName() {
        return cardHolderName;
    }

    public void setCardHolderName(String cardHolderName) {
        this.cardHolderName = cardHolderName;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public List<Transaction> getTransactions() {
        return transactions;
    }

    public void setTransactions(List<Transaction> transactions) {
        this.transactions = transactions;
    }
}

